angular.module('TagPrint')

.factory('TagPrintHomeService', ['$q', 'Http',
    function($q, Http) {
    	//获取barcode信息
        function getBarcodeData(Barcode) {
            var deferred = $q.defer();
            Http.post({
                url: "/api/CheckWork/getBarcodeData",
                data: {
                    Parameter: {
                        Barcode: Barcode    
                    }
                }
            }).then(function(data) {
                deferred.resolve(data);
            }, function(err) {
                deferred.reject(err);
            });
            return deferred.promise;
        }
        //提交标签打印的信息
        function submitTagPrint(barcodeData,deviceId,deviceName,workId,workName,WorkLocationId,WorkLocationName,userId) {
             
            var deferred = $q.defer();
            Http.post({
                url: "/api/TagPrint/submitTagPrint",
                data: {
                    Parameter: {
                        barcodeData: barcodeData,  
                        Terminal: deviceId,
                        TerminalName: deviceName,
                        Work: workId,
                        WorkName: workName,
                        WorkLocation: WorkLocationId,
                        WorkLocationName: WorkLocationName,
                        userId:userId
                        
                    }
                }
            }).then(function(data) {
                deferred.resolve(data);
            }, function(err) {
                deferred.reject(err);
            });
            return deferred.promise;
        }

        //更新标签打印的信息
        function updateTagPrint(barcodeData,userId) {
             
            var deferred = $q.defer();
            Http.post({
                url: "/api/TagPrint/updateTagPrint",
                data: {
                    Parameter: {
                        barcodeData: barcodeData,  
                        
                        userId:userId
                        
                    }
                }
            }).then(function(data) {
                deferred.resolve(data);
            }, function(err) {
                deferred.reject(err);
            });
            return deferred.promise;
        }

        //获取扩展枚举（班别）
        function getClasses(code) {
            var deferred = $q.defer();
            Http.post({
                url: "/api/CheckWork/getExtendEnumByCode",
                data: {
                    Parameter: {
                        code: code,   
                    }
                }
            }).then(function(data) {
                deferred.resolve(data);
            }, function(err) {
                deferred.reject(err);
            });
            return deferred.promise;
        }

        return {
            getBarcodeData: getBarcodeData,
            submitTagPrint: submitTagPrint,
            updateTagPrint: updateTagPrint,
            getClasses: getClasses
        };

    }
]);